package com.kg.fiber.view;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
import javax.swing.border.MatteBorder;

import com.kg.fiber.service.NodeModal;
import java.awt.SystemColor;

public class NodePanel extends JPanel implements ListCellRenderer<NodeModal>{

	/**
	 * 
	 */
	private static final long serialVersionUID = 3647579846725472636L;
	private JLabel labelIndex;
	private JLabel labelHost;
	private JLabel labelMark;
	private JLabel labelState;

	/**
	 * Create the panel.
	 */
	public NodePanel() {
		setBorder(new MatteBorder(0, 0, 1, 0, (Color) Color.LIGHT_GRAY));
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{5, 100, 200, 0, 100, 5, 0};
		gridBagLayout.rowHeights = new int[]{0, 0};
		gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 1.0, 0.0, 0.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{1.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		
		labelIndex = new JLabel("序号");
		labelIndex.setFont(new Font("微软雅黑", Font.PLAIN, 18));
		GridBagConstraints gbc_labelIndex = new GridBagConstraints();
		gbc_labelIndex.fill = GridBagConstraints.VERTICAL;
		gbc_labelIndex.insets = new Insets(0, 0, 0, 5);
		gbc_labelIndex.gridx = 1;
		gbc_labelIndex.gridy = 0;
		add(labelIndex, gbc_labelIndex);
		
		labelHost = new JLabel("网络地址");
		labelHost.setFont(new Font("微软雅黑", Font.PLAIN, 18));
		GridBagConstraints gbc_labelHost = new GridBagConstraints();
		gbc_labelHost.fill = GridBagConstraints.VERTICAL;
		gbc_labelHost.insets = new Insets(0, 0, 0, 5);
		gbc_labelHost.gridx = 2;
		gbc_labelHost.gridy = 0;
		add(labelHost, gbc_labelHost);
		
		labelMark = new JLabel("描述");
		labelMark.setFont(new Font("微软雅黑", Font.PLAIN, 18));
		GridBagConstraints gbc_labelMark = new GridBagConstraints();
		gbc_labelMark.anchor = GridBagConstraints.WEST;
		gbc_labelMark.fill = GridBagConstraints.VERTICAL;
		gbc_labelMark.insets = new Insets(0, 0, 0, 5);
		gbc_labelMark.gridx = 3;
		gbc_labelMark.gridy = 0;
		add(labelMark, gbc_labelMark);
		
		labelState = new JLabel("状态");
		labelState.setFont(new Font("微软雅黑", Font.PLAIN, 18));
		GridBagConstraints gbc_labelState = new GridBagConstraints();
		gbc_labelState.fill = GridBagConstraints.VERTICAL;
		gbc_labelState.insets = new Insets(0, 0, 0, 5);
		gbc_labelState.gridx = 4;
		gbc_labelState.gridy = 0;
		add(labelState, gbc_labelState);

	}

	@Override
	public Component getListCellRendererComponent(JList<? extends NodeModal> list, NodeModal value, int index,
			boolean isSelected, boolean cellHasFocus) {
		
		this.setPreferredSize(new Dimension(10, 64));
		
		
		this.labelIndex.setText(Integer.toString(index + 1));
		
		this.labelHost.setText(value.getNode().getHost());
		this.labelMark.setText(value.getNode().getMark());
		this.labelState.setText(value.getState().getMark());

		this.setBackground(isSelected ? SystemColor.activeCaption : Color.WHITE);
		
		return this;
	}
	
	
	
	

}
